<?php

class bd extends PDO {

    private $dsn = 'mysql:dbname=baconlanches;host=localhost;port=3306';
    private $user = 'root';
    private $password = '';
    private static $link = null;

    function __construct() {
        set_time_limit(50000);
        try {
            if (self::$link == null) {
                self::$link = parent::__construct($this->dsn, $this->user, $this->password);
                return self::$link;
            }
        } catch (PDOException $e) {
            echo 'Connection failed: ' . $e->getMessage();
            return false;
        }
    }

    public function ocorreramErros($stmt) {
        if ($stmt->errorCode() != 0) {
            $msg = $stmt->errorInfo();
            echo '<h3>Operação efetuada com erro:' . $stmt->errorCode() . $msg[1] . ' - ' . $msg[2] . '</h3>';
            throw new Exception("Operação do BD falhou",null, null);
        }
    }

    function __destruct() {
        self::$link = NULL;
    }

}

?>
